<template>
  <button
    class="grimm-btn"
    :type="nativeType"
    :disabled="disabled"
    :class="['grimm-btn-' + type, 'grimm-btn-' + size, block? 'grimm-btn-block': '']"
    @click="handleClick"
  >
    <i :class="icon" v-if="icon"></i>
    <slot>button</slot>
  </button>
</template>
<script>
const COMPONENT_NAME = 'grimm-button';
export default {
  name: COMPONENT_NAME,
  props: {
    icon: {
      type: String,
      default: '',
    },
    active: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    block: {
      type: Boolean,
      default: false,
    },
    nativeType: {
      type: String,
      default: 'button',
    },
    type: {
      type: String,
      default: 'default',
      validator(value) {
        return ['default', 'primary', 'secondary'].indexOf(value) > -1;
      },
    },
    size: {
      type: String,
      default: 'default',
      validator(value) {
        return ['default', 'large', 'mini', 'medium'].indexOf(value) > -1;
      },
    },
  },
  methods: {
    handleClick(e) {
      if (this.disabled) {
        e.preventDefault();
        e.stopPropagation();
        return;
      }
      this.$emit('click', e);
    },
  },
};
</script>
<style lang="stylus" >
@import '../../common/stylus/variable.styl';

// 默认图标样式及尺寸
.grimm-btn {
  appearance: none;
  margin: 0;
  font-size: $fontsize-large;
  text-align: center;
  box-sizing: border-box;
  padding: 0 $btn-padding-default;
  border-radius: $radius-size-regular;
  color: $color-red;
  display: inline-block;
  outline: none;
  border: none;
  overflow: hidden;
  position: relative;
  text-align: center;
  cursor: pointer;
  background-color: $color-background;
  color: $color-btn-default;
  border: 1px solid rgba(244, 67, 54, 0.5);
  height: $btn-height-default;
  line-height: 1;
  font-size: $fontsize-default;
  white-space: nowrap;

  &:disabled {
    color: $color-btn-disabled-font;
    border: 1px solid $color-btn-border;
    background-color: $color-background;
  }

  &:active {
    background-color: $color-btn-active-bg;
    color: $color-btn-active;
    border: 1px solid $color-btn-active-border;
  }
}

.grimm-btn-primary {
  background-color: $color-red;
  color: $color-white;
  border: 1px solid $color-red;

  &:disabled {
    background-color: $color-btn-disabled;
    border: 1px solid transparent;
  }

  &:active {
    background-color: $color-btn-active-bg-primary;
    color: $color-btn-active-primary;
    border: 1px solid transparent;
  }
}

.grimm-btn-secondary {
  background-color: $color-white;
  color: $color-btn-secondary;
  border: 1px solid $color-btn-border;

  &:active {
    background-color: $color-btn-active-bg-secondary;
    color: $color-btn-secondary;
    border: 1px solid $color-btn-active-border-secondary;
  }
}

.grimm-btn-large {
  height: $btn-height-large;
  font-size: $fontsize-large;
}

.grimm-btn-medium {
  height: $btn-height-medium;
  font-size: $fontsize-medium;
}

.grimm-btn-mini {
  height: $btn-height-mini;
  font-size: $fontsize-mini;
}

.grimm-btn-block {
  display: block;
  width: 100%;
}
</style>